package com.flower.service.impl;
import com.flower.model.entity.Sort;
import com.flower.mapper.SortMapper;
import com.flower.result.PageResult;
import com.flower.service.ISortService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lm
 * @create 2022-03-26 15:23
 */
@Service
public class SortServiceImpl implements ISortService {

    @Autowired
    private SortMapper sortMapper;

    @Override
    public PageResult findPage(Page<Sort> page, String sortname) {
        PageHelper.startPage(page);
        Page<Sort> pageResult = sortMapper.findPage(page,sortname);
        return new PageResult(pageResult.getTotal(),pageResult.getResult());
    }

    @Override
    public PageResult findPage1(Page<Sort> page) {
        PageHelper.startPage(page);
        Page<Sort> pageResult = sortMapper.findPage1(page);
        return new PageResult(pageResult.getTotal(),pageResult.getResult());
    }

    @Override
    public void saveOrUpdate(Sort sort) {
        if (sort.getId()==null){
            sortMapper.add(sort);
        }
        else {
            sortMapper.update(sort);
        }
    }

    @Override
    public void removeById(Integer id) {
        sortMapper.removeById(id);
    }

    @Override
    public void removeByIds(List<Integer> ids) {
        ids.forEach(id -> sortMapper.removeById(id));
    }

    @Override
    public List<Sort> list() {
        return sortMapper.list();
    }

    @Override
    public Sort getById(Integer id) {
        return sortMapper.getById(id);
    }
}
